var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e;
} : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
}, app = getApp();

Page({
    data: {
        sign_up: [ {
            name: "姓名"
        }, {
            name: "手机号"
        } ]
    },
    onLoad: function(e) {
        var t = this;
        console.log(e), t.setData({
            price: e.price,
            activity_id: e.activity_id
        }), console.log(e.activity_id), app.util.request({
            url: "entry/wxapp/Gethdbm",
            cachetime: "0",
            data: {
                activity_id: e.activity_id
            },
            success: function(e) {
                if (console.log("获取报名信息"), console.log(e), 0 == e.data.length) {
                    var o = t.data.sign_up;
                    t.setData({
                        sign_up: o
                    });
                } else t.setData({
                    sign_up: e.data
                });
            }
        }), app.getUserInfo(function(e) {
            console.log(e), t.setData({
                user_id: e.id,
                openid: e.openid
            });
        }), t.refresh();
    },
    refresh: function(e) {
        var o = wx.getStorageSync("tickets"), t = [];
        o.map(function(e) {
            var o = {};
            o.gm_num = e.num, o.money = e.money, o.bm_check = e.bm_check, o.tk_name = e.tk_name, 
            o.ticket_id = e.id, t.push(o);
        }), console.log(t), this.setData({
            tickets: o,
            ticket: t
        }), console.log(o);
    },
    formSubmit: function(e) {
        for (var n = this, a = e.detail.formId, o = n.data.sign_up, t = e.detail.value, i = "", c = 0; c < o.length; c++) o[c].value = t["name" + c], 
        "" == o[c].value && (i = "请输入您的" + o[c].name);
        if ("" != i) wx.showModal({
            title: "温馨提示",
            content: i
        }); else {
            console.log("输入完全了");
            var s = n.data.ticket, l = n.data.user_id, u = n.data.activity_id, r = n.data.price, d = n.data.openid;
            console.log("活动id为" + u), console.log("用户id为" + l), console.log("需要支付的金额为" + r), 
            console.log("用户的openid为" + d), console.log("这是报名信息"), console.log(o), console.log(void 0 === o ? "undefined" : _typeof(o)), 
            console.log("这是票券信息"), console.log(s), console.log(void 0 === s ? "undefined" : _typeof(s)), 
            r <= 0 ? app.util.request({
                url: "entry/wxapp/savebm",
                cachetime: "0",
                data: {
                    activity_id: u,
                    user_id: l,
                    ticket: s,
                    bm: o
                },
                success: function(e) {
                    console.log("提交报名"), console.log(e);
                    var o = e.data, t = wx.getStorageSync("userInfo").openid;
                    app.util.request({
                        url: "entry/wxapp/Message1",
                        cachetime: "0",
                        data: {
                            form_id: a,
                            openid: t,
                            bm_id: o
                        },
                        success: function(e) {
                            console.log("发送模板消息"), console.log(e);
                        }
                    }), wx.redirectTo({
                        url: "fill_success?price=" + n.data.price
                    });
                }
            }) : app.util.request({
                url: "entry/wxapp/savebm",
                cachetime: "0",
                data: {
                    activity_id: u,
                    user_id: l,
                    ticket: s,
                    bm: o
                },
                success: function(e) {
                    console.log("保存报名"), console.log(e);
                    var t = e.data;
                    app.util.request({
                        url: "entry/wxapp/Pay",
                        cachetime: "0",
                        data: {
                            openid: d,
                            money: r,
                            bm_id: t
                        },
                        success: function(e) {
                            wx.requestPayment({
                                timeStamp: e.data.timeStamp,
                                nonceStr: e.data.nonceStr,
                                package: e.data.package,
                                signType: e.data.signType,
                                paySign: e.data.paySign,
                                success: function(e) {
                                    console.log("支付成功"), console.log(e);
                                    var o = wx.getStorageSync("userInfo").openid;
                                    app.util.request({
                                        url: "entry/wxapp/Message1",
                                        cachetime: "0",
                                        data: {
                                            form_id: a,
                                            openid: o,
                                            bm_id: t
                                        },
                                        success: function(e) {
                                            console.log("发送模板消息"), console.log(e);
                                        }
                                    }), wx.redirectTo({
                                        url: "fill_success?price=" + n.data.price
                                    });
                                },
                                fail: function(e) {
                                    console.log("支付失败"), console.log(e), wx.showToast({
                                        title: "支付失败",
                                        duration: 1e3
                                    });
                                }
                            });
                        }
                    });
                }
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});